//
//  MacroUtility.h
//  MoXiProject
//
//  Created by 周筱雯 on 2017/5/26.
//  Copyright © 2017年 周筱雯. All rights reserved.
//

#ifndef MacroUtility_h
#define MacroUtility_h


#define DEF_MAX(a,b,c) (a>b?(a>c?a:c):(b>c?b:c))

#define DEF_TWO_MAX(a,b) (a>b?a:b)


#define DEF_RESIZE_UI(float)         ((float)/375.0f*DEF_DEVICE_WIDTH)

#define DEF_PAGESIZE @"10"
/**
 *字符串去左右空格
 */
#define DEF_DROP_WHITESPACE(x) [x stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]



/**
 *字体
 */
#define DEF_MyFont(x)     [UIFont systemFontOfSize:x]
#define DEF_MyBoldFont(x) [UIFont boldSystemFontOfSize:x]

/**
 *设置图片
 */
#define DEF_IMAGENAME(name)         [UIImage imageNamed:name]
#define DEF_BUNDLE_IMAGE(name,type) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:name ofType:type]]


/**
 *根据RGB获取color
 */
#define DEF_COLOR_RGBA(r,g,b,a)      [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define DEF_COLOR_RGB(r,g,b)         [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:1.0f]
#define DEF_UICOLORFROMRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

#define DEF_NORMAL_DEFAULT_IMAGE [UIImage imageNamed:@"nourlImg"]



/** 屏幕size */
#define LTSize [UIScreen mainScreen].bounds.size

/**  高度百分比*/
#define LTPercentage(a) (LTSize.height*((a)/667.00))

/**  宽度百分比*/
#define LTWPercentage(a) (LTSize.width*((a)/375.00))

/**
 *获取AppDelegate
 */
#define DEF_MyAppDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)

/**
 *获取APP当前版本号
 */
#define DEF_AppCurrentVersion [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]


/**
 *获取APP当前版本号
 */
#define DEF_App_BundleId [[NSBundle mainBundle] bundleIdentifier]
/**
 *Document路径
 */
#define DEF_DocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]

/**
 *NSUserDefault
 */
#define DEF_UserDefaults [NSUserDefaults standardUserDefaults]

/**
 *获取屏幕宽高
 */
#define DEF_DEVICE_WIDTH                [UIScreen mainScreen].bounds.size.width
#define DEF_DEVICE_HEIGHT               [UIScreen mainScreen].bounds.size.height
#define DEF_CONTENT_INTABBAR_HEIGHT     (DEF_DEVICE_IphoneX ? ([UIScreen mainScreen].bounds.size.height - 88):([UIScreen mainScreen].bounds.size.height - 64))

#define DEF_NAVIGATIONBAR_HEIGHT        64
#define DEF_TABBAR_HEIGHT               49
/**
 *获取iphone
 */
#define DEF_DEVICE_IphoneX               (([[UIScreen mainScreen] bounds].size.height-812)?NO:YES)
#define DEF_DEVICE_Iphone6p              (([[UIScreen mainScreen] bounds].size.height-736)?NO:YES)
#define DEF_DEVICE_Iphone6               (([[UIScreen mainScreen] bounds].size.height-667)?NO:YES)
#define DEF_DEVICE_Iphone5               (([[UIScreen mainScreen] bounds].size.height-568)?NO:YES)
#define DEF_DEVICE_Iphone4               (([[UIScreen mainScreen] bounds].size.height-480)?NO:YES)


//app常用功能
#define DEF_APP_NAME    [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]
#define DEF_APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define DEF_APP_OS      [[[NSBundle mainBundle] infoDictionary] objectForKey:@"DTPlatformVersion"]

//Tim添加，计算二级页面的content的高度
#define DEF_CONTENT_WITHOUTTABBAR_HEIGHT (DEF_IOS7 ? ([UIScreen mainScreen].bounds.size.height - 64):([UIScreen mainScreen].bounds.size.height - 84))

/**
 *所有类型转化成String(防止出现nill值显示在UI)
 */
#define DEF_OBJECT_TO_STIRNG(object) ((object && object != (id)[NSNull null] && ([object isKindOfClass:[NSNumber class]] || ![object isEqualToString:@"<null>"]))?([object isKindOfClass:[NSString class]]?object:[NSString stringWithFormat:@"%@",object]):@"")

/* *
 *iOS版本
 */
#define DEF_IOS7         ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 ? YES : NO)
#define DEF_IOS7Dot0     ([[[UIDevice currentDevice] systemVersion] floatValue] == 7.0 ? YES : NO)
#define DEF_IOS8         ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 ? YES : NO)

// 判断iPhoneX
#define isiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define iPhoneX [[UIScreen mainScreen] bounds].size.width >= 375.0f && [[UIScreen mainScreen] bounds].size.height >= 812.0f && isiPhone

/**
 *设备方向
 */
#define DEF_Portrait            ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortrait ? YES : NO)
#define DEF_PortraitUpsideDown  ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationPortraitUpsideDown ? YES : NO)
#define DEF_LandscapeLeft       ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeLeft ? YES : NO)
#define DEF_LandscapeRight      ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeRight ? YES : NO)

#define iconWeight (DEF_DEVICE_WIDTH-30*4)/3

#undef	BLOCK_SAFE
#define BLOCK_SAFE(block)           if(block)block
////是否输出日志
#define __DEBUG_

#ifdef DEBUG
//#define NSLog(format, ...) printf("class: <%p %s:(%d) > method: %s \n%s\n", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String] )
#define NSLog(...) printf("%f %s\n",[[NSDate date]timeIntervalSince1970],[[NSString stringWithFormat:__VA_ARGS__]UTF8String]);
#else
#define NSLog(format, ...)
#endif

#endif /* MacroUtility_h */
